<#if roles.bzjManager && roles.canManageContract && roles.contractMain>
<div class="col-md-12 contract-bzj">
	<div class="panel panel-primary">
		<div class="panel-heading">
			<h3 class="panel-title">
				<i class="icon-signin icon-large"></i>
				7日内待收回的质保金（保函）
			</h3>
		</div>
		<#if contractBzj?? && contractBzj?size &gt; 0>
		<table class="table table-hover">
			<tr>
				<th class="text-center" width="75">操作</th>
				<th class="text-center" width="110">类型</th>
				<th class="text-center" width="185">金额</th>
				<th class="text-center" width="135">应收日期</th>
				<th class="">合同信息</th>
			</tr>
			<#list contractBzj as b>
			<!--  -->
			<tr class="${((b[0].overDate)?string('text-danger',''))}" style="cursor: pointer;" data-cid="${b[1]}" data-mid="${b[0].id}">
				<td class="text-center">
					<div class="btn btn-danger btn-xs back-bzj">收回</div>
				</td>
				<td class="text-center cell-for-open name">${b[0].name}</td>
				<td class="text-center cell-for-open total">${(b[0].total?string('currency'))!'-'}</td>
				<td class="text-center cell-for-open time">${(b[0].backTime?string('yyyy-MM-dd'))!'-'}</td>
				<td class="cell-for-open contract">[No.]&nbsp;${b[3]}&nbsp;-&nbsp;${b[2]}</td>
			</tr>
			</#list>
		</table>

		<script type="text/javascript">
			require([ 'suredy' ], function() {
				// 打开合同
				$('.contract-bzj').on('click', '.cell-for-open', function() {
					var $this = $(this);
					var tr = $this.parent('tr');
					var cid = tr.data('cid');

					window.open('${request.contextPath}/contract/view/' + cid, '_blank');
				});

				// 回收
				$('.contract-bzj').on('click', '.btn.back-bzj', function() {
					var $this = $(this);
					var tr = $this.parents('tr');
					var mid = tr.data('mid'); // 保证金id

					var msg = '确认收回资金？\n\n';
					msg += '合同：' + tr.find('td.contract').text() + '\n';
					msg += '类型：' + tr.find('td.name').text() + '\n';
					msg += '金额：' + tr.find('td.total').text() + '\n';

					if (!confirm(msg)) {
						return false;
					}

					$.ajax({
						url : '${request.contextPath}/money/back',
						data : {
							moneyId : mid
						},
						type : 'post',
						dataType : 'json',
						success : function(result, textStatus, jqXHR) {
							if (!result || !result.success) {
								var msg = (result && result.msg) || '操作失败！';
								alert(msg);
								return false;
							}

							Suredy.loadContent('${request.contextPath}/front-page');
						},
						error : function(jqXHR, textStatus, errorThrown) {
							alert('操作失败！\n\n' + errorThrown);
						}

					});

					return false;
				});
			});
		</script>
		<#else>
		<div class="panel-body text-danger">暂无数据！</div>
		</#if>
	</div>
</div>
</#if>
